package com.gaokuo.es.compose;

import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

/**
 * @author gaokuo
 */
public class DefaultConditionBuild {

    public QueryBuilder getQueryBuilder(ComposeConditionNode node){
        switch (node.condition){
            case term:
                return QueryBuilders.termsQuery(node.property,node.compareTo);
            case match:
                return QueryBuilders.matchQuery(node.property,node.compareTo);
            case gte:
                return QueryBuilders.rangeQuery(node.property).gte(node.compareTo);
            case gt:
                return QueryBuilders.rangeQuery(node.property).gt(node.compareTo);
            case lte:
                return QueryBuilders.rangeQuery(node.property).lte(node.compareTo);
            case lt:
                return QueryBuilders.rangeQuery(node.property).lt(node.compareTo);
            default: return null;
        }
    }
}
